package com.fast.fastenjoy.base.web.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public final class ActionContext {

	private static final ThreadLocal<ActionContext> actionContextThreadLocal = new ThreadLocal<ActionContext>();
	
	/**
     * 当前对象只给自己实例
     */
    private ActionContext(){
    }
	
    private HttpServletRequest request;

    private HttpServletResponse response;
    
    public static ActionContext getActionContext() {
        return actionContextThreadLocal.get();
    }
    
    public static void createActionContext(HttpServletRequest request, HttpServletResponse response){
    	
    	ActionContext ctx = new ActionContext();
        
    	ctx.request = request;
        ctx.response = response;
        
        actionContextThreadLocal.set(ctx);
    }
    
    public static void destroyActionContext() {
        actionContextThreadLocal.remove();
    }

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public HttpSession getHttpSession() {
        return request.getSession();
    }
    
}
